#include <Windows.h>
#include <tchar.h>
#include "resource.h"
#pragma data_seg("share_data_sec")
int nInsArray[256] = {0};
#pragma data_seg()
#pragma comment(linker, "/SECTION:share_data_sec,RWS") 

int CALLBACK DlgProc(HWND hDlg, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
	static int nInsIndex = 0;
	switch (nMsg)
	{
		case WM_INITDIALOG:
		{
			UINT nWidth		= GetSystemMetrics(SM_CXSCREEN);
			UINT nHeight	= GetSystemMetrics(SM_CYSCREEN);
			RECT rtClient;
			GetClientRect(hDlg, &rtClient);
			SetWindowPos(hDlg, NULL, (nWidth - (rtClient.right - rtClient.left)) / 2, (nHeight - (rtClient.bottom - rtClient.top)) / 2, 0, 0, SWP_NOSIZE);
			
			for (int ii = 0; ii < sizeof(nInsArray)/sizeof(*nInsArray); ii++)
			{
				if (nInsArray[ii] == 0)
				{
					nInsArray[ii] = 1;
					nInsIndex = ii;
					break;
				}
			}
			
			if (nInsIndex > 0)
			{
				TCHAR szCaption[MAX_PATH];
				_stprintf(szCaption, _T("[%d]Demo0112"), nInsIndex + 1);
				SetWindowText(hDlg, szCaption);
			} else {
				SetWindowText(hDlg, _T("Demo0112"));
			}
						
			break;
		}
		case WM_COMMAND:
		{
			break;
		}
		case WM_CLOSE:
		{
			nInsArray[nInsIndex] = 0;
			PostQuitMessage(0);
			break;
		}
	}

	return 0;
}

BOOL WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPreInstance, LPTSTR szCmdLine, int nShowCmd)
{
	DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG), NULL, DlgProc);

	return TRUE;
}